//
//  PPNetRequest.h
//  PPNetworking
//
//  Created by 邓标祥 on 2020/12/15.
//

#import <Foundation/Foundation.h>
#import "PPNetConst.h"
NS_ASSUME_NONNULL_BEGIN

@interface PPNetRequest : NSObject

+ (instancetype)request;

@property (nonatomic, copy) NSString *key;

/** 任务唯一标识 */
@property (nonatomic, copy, readonly) NSString *identifier;

/** 服务器地址 */
@property (nonatomic, copy, nullable) NSString *server;

/** 相对路径 */
@property (nonatomic, copy, nullable) NSString *api;

/** 完成的url地址，由服务器和相对路径组成 */
@property (nonatomic, copy, nullable) NSString *url;

/** 请求参数 */
@property (nonatomic, strong, nullable) NSDictionary<NSString *, id> *parameters;

/** 请求头 */
@property (nonatomic, strong, nullable) NSDictionary<NSString *, NSString *> *headers;

@property (nonatomic, assign) BOOL useGeneralServer;        //!< 是否使用通用服务器地址
@property (nonatomic, assign) BOOL useGeneralHeaders;       //!< 是否使用通用请求头
@property (nonatomic, assign) BOOL useGeneralParameters;    //!< 是否添加通用参数

/** 请求类型 */
@property (nonatomic, assign) PPNetRequestType requestType;

/** HTTP的类型 */
@property (nonatomic, assign) PPNetHTTPMethodType httpMethod;

/** 请求的序列化类型 */
@property (nonatomic, assign) PPNetRequestSerializerType requestSerializerType;

/** 响应的序列化类型 */
@property (nonatomic, assign) PPNetResponseSerializerType responseSerializerType;

/** 超时 */
@property (nonatomic, assign) NSTimeInterval timeoutInterval;

/** 成功block */
@property (nonatomic, copy, readonly, nullable) PPNetSuccessBlock successBlock;

/** 失败的block */
@property (nonatomic, copy, readonly, nullable) PPNetFailureBlock failureBlock;

/** 请求结束的block */
@property (nonatomic, copy, readonly, nullable) PPNetFinishedBlock finishedBlock;

/** 是否进行数据解析 */
@property (nonatomic, assign) BOOL isAnalyticData;

@property (nonatomic, strong) Class classModel;

- (void)cleanCallbackBlocks;

/// 用于子类去处理对应的业务数据的解析结构
/// @param responseObject 业务数据
/// @param resultBlock reslutBlock
- (void)classModelWithResponseObject:(id _Nonnull)responseObject onResultBlock:(PPNetJsonResultBlock)resultBlock;

/// 添加Header
/// @param headers headers字典
- (void)addHeader:(NSDictionary<NSString *, NSString *> *)headers;

@end

/// ************************************ 全省港澳所有既分割线唯独呢条至靓仔 ************************************ ///

@interface PPNetBatchRequest : NSObject

/** 任务唯一标识 */
@property (nonatomic, copy, readonly) NSString *identifier;

@property (nonatomic, strong, readonly) NSMutableArray *requestArray;
@property (nonatomic, strong, readonly) NSMutableDictionary *responseDict;
@property (nonatomic, strong, readonly) NSMutableDictionary *errorDict;

- (void)addRequest:(PPNetRequest *)request;
- (void)addRequestArray:(NSArray<PPNetRequest *>*)array;

- (BOOL)onFinishedOneRequest:(PPNetRequest *)request
                    response:(nullable id)responseObject
                       error:(nullable NSError *)error;


- (void)cleanCallbackBlocks;
@end

/// ************************************ 全省港澳所有既分割线唯独呢条至靓仔 ************************************ ///

@interface PPNetBatchResult : NSObject
@property (nonatomic, strong) NSMutableDictionary *responseDict;
@property (nonatomic, strong) NSMutableDictionary *errorDict;


/// 根据key值获取对应的请求结果，返回正确数据或者error信息对象
/// @param key key
- (_Nullable id)resultForKey:(NSString *)key;
- (PPNetError *)errorResultForKey:(NSString *)key;

@end

NS_ASSUME_NONNULL_END
